<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "attention".
 *
 * @property integer $uid
 * @property integer $qid
 */
class Attention extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'attention';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['uid', 'qid'], 'required'],
            [['uid', 'qid'], 'integer']
        ];
    }

    public function getQa() {
        return $this->hasOne(Qa::className(), ['id' => 'qid']);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'uid' => '用户ID',
            'qid' => '问答ID',
        ];
    }

    public function check($qid) {
        $uid = Yii::$app->user->identity->id;
        $result = Attention::findOne(['uid' => $uid, 'qid' => $qid]);
        return $this->render('/widgets/attention', ['result' => $result, 'qid' => $qid]);
    }

}
